﻿/***************************************************************************
 *		ElGee Google Chart API Helper
 *		Copyright(C) 2011 by Laurent Geffroy lgeffroy@gmail.com
 * 
 *		This program is free software; you can redistribute it and/or 
 *		modify it under the terms of the GNU General Public License as
 *		published by the Free Software Foundation; either version 2 of 
 *		the License, or (at your option) any later version.
 *		
 *		This program is distributed WITHOUT ANY WARRANTY; without even the
 *		implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
 *		See the GNU General Public License for more details.
 *	
 *      For particular licensing, please contact me at lgeffroy@gmail.com
 *****************************************************************************/

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;

namespace ElGee.Google.Charts
{
    /// <summary>
    /// Style for the Gauge
    /// </summary>
    public class GaugeStyle : ChartBase
    {
        /// <summary>
        /// Gets or sets the green from.
        /// The lowest value for a range marked by a green color.
        /// </summary>
        /// <value>The green from.</value>
        public Int32 GreenFrom {get; set;}

        /// <summary>
        /// Gets or sets the green to.
        /// The highest value for a range marked by a green color.
        /// </summary>
        /// <value>The green to.</value>
        public Int32 GreenTo { get; set; }

        /// <summary>
        /// Gets or sets the height.
        /// Height of the chart in pixels.
        /// </summary>
        /// <value>The height.</value>
        public UInt32 Height { get; set; }


        /// <summary>
        /// Gets or sets the width.
        /// Width of the chart in pixels.
        /// </summary>
        /// <value>The width.</value>
        public UInt32 Width { get; set; }

        /// <summary>
        /// Gets or sets the max.
        /// The maximal value of a gauge
        /// </summary>
        /// <value>The max.</value>
        public Int32 Max { get; set; }

        /// <summary>
        /// Gets or sets the min.
        /// The minimal value of a gauge
        /// </summary>
        /// <value>The min.</value>
        public Int32 Min { get; set; }

        /// <summary>
        /// Gets or sets the minor ticks.
        /// The number of minor tick section in each major tick section.
        /// </summary>
        /// <value>The minor ticks.</value>
        public UInt32 MinorTicks { get; set; }

        /// <summary>
        /// Gets or sets the major ticks.
        /// Labels for major tick marks. The number of labels define the number of major ticks in all gauges. The default is five major ticks, with the labels of the minimal and maximal gauge value.
        /// </summary>
        /// <value>The major ticks.</value>
        public List<String> MajorTicks { get; private set; }

        /// <summary>
        /// Gets or sets the red from.
        /// The lowest value for a range marked by a red color.
        /// </summary>
        /// <value>The green from.</value>
        public Int32 RedFrom { get; set; }

        /// <summary>
        /// Gets or sets the red to.
        /// The highest value for a range marked by a red color.
        /// </summary>
        /// <value>The green to.</value>
        public Int32 RedTo { get; set; }

        /// <summary>
        /// Gets or sets the red from.
        /// The lowest value for a range marked by a yellow color.
        /// </summary>
        /// <value>The green from.</value>
        public Int32 YellowFrom { get; set; }

        /// <summary>
        /// Gets or sets the yellow to.
        /// The highest value for a range marked by a yellow color.
        /// </summary>
        /// <value>The green to.</value>
        public Int32 YellowTo { get; set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="GaugeStyle"/> class.
        /// </summary>
        public GaugeStyle()
        {
            GreenFrom = Int32.MinValue;
            GreenTo = Int32.MinValue;
            Height = 0;
            Width = 0;
            MajorTicks = new List<string>();
            Min = 0;
            Max = 100;
            MinorTicks = 2;
            RedFrom = Int32.MinValue;
            RedTo = Int32.MinValue;
            YellowFrom = Int32.MinValue;
            YellowTo = Int32.MinValue;
        }

        /// <summary>
        /// Returns a <see cref="System.String"/> that represents this instance.
        /// </summary>
        /// <returns>
        /// A <see cref="System.String"/> that represents this instance.
        /// </returns>
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            // GreenFrom
            if (GreenFrom > Int32.MinValue)
                sb.Append("greenFrom: ").Append(GreenFrom.ToString(CultureInfo.InvariantCulture)).Append(",");

            // GreenTo
            if (GreenTo > Int32.MinValue)
                sb.Append("greenTo: ").Append(GreenTo.ToString(CultureInfo.InvariantCulture)).Append(",");

            // Height
            if (Height > 0)
                sb.Append("height: ").Append(Height.ToString(CultureInfo.InvariantCulture)).Append(",");

            // Width
            if (Width > 0)
                sb.Append("width: ").Append(Width.ToString(CultureInfo.InvariantCulture)).Append(",");

            // MajorTicks
            if ((MajorTicks != null) && (MajorTicks.Count > 0))
            {

                sb.Append("majorTicks: [");
                for (int i = 0; i < MajorTicks.Count; i++)
                {
                    sb.Append("'").Append(SecureString(MajorTicks[i])).Append("',");
                }
                // Removing the last comma of the MajorTicks
                sb.Remove(sb.Length - 1, 1);
                sb.Append("],");
            }

            // Min
            if (Min > 0)
                sb.Append("min: ").Append(Min.ToString(CultureInfo.InvariantCulture)).Append(",");

            // Max
            if (Max > 0)
                sb.Append("max: ").Append(Max.ToString(CultureInfo.InvariantCulture)).Append(",");

            // MinorTicks
            if (MinorTicks != 2)
                sb.Append("minorTicks: ").Append(MinorTicks.ToString(CultureInfo.InvariantCulture)).Append(",");

            // RedFrom
            if (RedFrom > Int32.MinValue)
                sb.Append("redFrom: ").Append(RedFrom.ToString(CultureInfo.InvariantCulture)).Append(",");

            // RedTo
            if (RedTo > Int32.MinValue)
                sb.Append("redTo: ").Append(RedTo.ToString(CultureInfo.InvariantCulture)).Append(",");
            
            // YellowFrom
            if (YellowFrom > Int32.MinValue)
                sb.Append("yellowFrom: ").Append(YellowFrom.ToString(CultureInfo.InvariantCulture)).Append(",");

            // YellowTo
            if (YellowTo > Int32.MinValue)
                sb.Append("yellowTo: ").Append(YellowTo.ToString(CultureInfo.InvariantCulture)).Append(",");

            // Removing the last comma
            sb.Remove(sb.Length - 1, 1);

            return sb.ToString();
        }
    }
}
